<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="物业名称" prop="pmid">

        <el-select v-model="queryParams.pmid" placeholder="请输入车场名称" clearable>
          <el-option
            v-for="item in carsManagement"
            :key="item.pmid"
            :label="item.propertyName"
            :value="item.pmid"
            @keyup.enter.native="handleQuery"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="车场名称" prop="hpid">
        <el-select v-model="queryParams.hpid" placeholder="请输入车场名称" clearable>
          <el-option
            v-for="item in carsHome"
            :key="item.chid"
            :label="item.chname"
            :value="item.chid"
            @keyup.enter.native="handleQuery"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="时间筛选">
        <el-date-picker
          v-model="daterangeCreateTime"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="车牌号">
                <el-input
                  v-model="queryParams.licenseNumber"
                  placeholder="请输入车牌号"
                  clearable
                  @keyup.enter.native="handleQuery"
                />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">刷新</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['pxy-cars:excrecord:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="excrecordList">
      <el-table-column label="序号" align="center" prop="erid" />
      <el-table-column label="物业名称" align="center" prop="propertyManagement.propertyName" />
      <el-table-column label="车场名称" align="center" prop="carsHome.chname" />
      <el-table-column label="设备" align="center" prop="carsHomeEq.eqname"/>
      <el-table-column label="图片" align="center" prop="exceptionPic" />
      <el-table-column label="车牌号" align="center" prop="carsMsg.licenseNumber" />
      <el-table-column label="创建时间" align="center" prop="createTime"/>
      <el-table-column label="备注" align="center" prop="exceptionRemark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handlelist(scope.row)"
            v-hasPermi="['pxy-cars:excrecord:export']"
          >查看</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import { listExcrecord, getExcrecord, delExcrecord, addExcrecord, updateExcrecord } from "@/api/pxy-cars/excrecord";
import { listCarsHome} from "@/api/pxy-cars/carshome";
import { listPropertyManagement} from "@/api/pxy-cars/propertymanagement";


export default {
  name: "Excrecord",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 异常车辆记录表格数据
      excrecordList: [],
      carsManagement: [],
      carsHome: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      daterangeCreateTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        ohid: null,
        hpid: null,
        cmid: null,
        createTime: null,
        updateTime: null,
        licenseNumber: null
      },
      value1:[],
      // 表单参数
      form: {},
    };
  },
  created() {
    this.getList();
    this.getManagement();
    this.getHome();
  },
  methods: {
    /** 查询异常车辆记录列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeCreateTime && '' != this.daterangeCreateTime) {
        this.queryParams.params["beginCreateTime"] = this.daterangeCreateTime[0];
        this.queryParams.params["endCreateTime"] = this.daterangeCreateTime[1];
      }
      listExcrecord(this.queryParams).then(response => {
        this.excrecordList = response.rows;
        console.log(response.rows)
        this.total = response.total;
        this.loading = false;
      });
    },
    getHome() {
      this.loading = true;
      listCarsHome(this.queryParams).then(response => {
        this.carsHome = response.rows;
        // console.log(response.rows)
        this.loading = false;
      });
    },
    getManagement() {
      this.loading = true;
      listPropertyManagement(this.queryParams).then(response => {
        this.carsManagement = response.rows;
        // console.log(response.rows)
        this.loading = false;
      });
    },
    handlelist(row) {
      this.reset();
      const exceid = row.erid || this.ids
      console.log(exceid)
      getExcrecord(exceid).then(response => {
        this.form = response.data;
        console.log(this.form)
        this.$router.push({
          path: 'excrecordcheck',
          query: this.form
        })
      })
    },
    // 表单重置
    reset() {
      this.form = {
        erid: null,
        code: null,
        status: null,
        deleted: null,
        createTime: null,
        updateTime: null,
        ctid: null,
        exceptionRemark: null,
        exceptionPic: null,
        ohid: null,
        hpid: null
      };
      this.resetForm("form");
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams={}
      this.daterangeCreateTime=[]
      this.handleQuery();
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('pxy-cars/excrecord/export', {
        ...this.queryParams
      }, `excrecord_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
